<template>
  <div class="app-container">
    <el-button
      type="primary"
      icon="el-icon-edit"
      size="mini"
      @click="openDialog">添加</el-button>
    <el-table
      v-loading="listLoading"
      :data="list"
      class="supplier-table"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号" width="50">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="名称" width="150">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="地址">
        <template slot-scope="scope">
          <span>{{ scope.row.address }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务类型" width="100" align="center">
        <template slot-scope="scope">
          {{ scope.row.service_type }}
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="服务内容" width="250">
        <template slot-scope="scope">
          {{ scope.row.service_content }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="电话" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="联系人" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="备注" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.remarks }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="编辑"
      :visible.sync="centerDialogVisible"
      width="30%"
      center>
      <span>需要注意的是内容是默认不居中的</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import { getSupplierList } from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      centerDialogVisible: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getSupplierList().then(response => {
        this.list = response.data.items
        this.listLoading = false
      })
    },
    openDialog() {
      this.centerDialogVisible = true
    }
  }
}
</script>

<style>
.supplier-table{
  margin-top: 10px;
}
</style>
